package com.longdaji.decoration.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.longdaji.decoration.R;
import com.longdaji.decoration.bean.News;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Kanade on 2018/2/27 0027.
 */

public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.NewsHolder> {

    private List<News> mNewsList;
    private Context mContext;

    public NewsAdapter(List<News> newsList) {
        this.mNewsList = newsList;
    }

    @Override
    public NewsHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_news, parent, false);
        NewsHolder holder = new NewsHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(NewsHolder holder, int position) {
        News news = mNewsList.get(position);
        Glide.with(mContext).load(news.getUserPortraitUri()).into(holder.ivUserPortrait);
        holder.tvUserName.setText(news.getUserName());
        holder.tvNewsContent.setText(news.getNewsContent());
        holder.tvNewsTime.setText(news.getNewsTime());
    }

    @Override
    public int getItemCount() {
        return mNewsList.size();
    }

     class NewsHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_user_portrait)
        ImageView ivUserPortrait;
        @BindView(R.id.tv_user_name)
        TextView tvUserName;
        @BindView(R.id.tv_news_content)
        TextView tvNewsContent;
        @BindView(R.id.tv_news_time)
        TextView tvNewsTime;

        public NewsHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        // TODO: 2018/3/5 0005 onViewClicked
    }

}
